<template>
    <div class="container">
        <h2 class="title">{{ photolist.title }}</h2>
        <p class="subtitle">
            <span>发表时间：{{ photolist.add_time | dateFormat }}</span>
            <span>点击：{{ photolist.click }}次</span>
        </p>
        <hr>
        <!-- 缩略图区域 -->
        <vue-preview class="preview-img" :slides="list" @close="handleClose"></vue-preview>
        <!-- 图片内容区域 -->
        <div class="content" v-html="photolist.content"></div>
        <!-- 放置评论子组件 -->
        <comment-box :parentid="id"></comment-box>
    </div>
</template>

<script>
import {Toast} from 'mint-ui'
import comment from '../subcomponents/comment.vue'
export default {
    data(){
        return {
            id:this.$route.params.id,
            photolist:{},
            list:[]
        }
    },
    created(){
        this.getPhotoInfo()
        this.getThumbs()
    },
    methods:{
        getPhotoInfo(){
            this.$http.get('api/getimageInfo/' + this.id).then(result=>{
                if(result.body.status === 0){
                    this.photolist = result.body.message[0]
                }else{
                    Toast("图片详情获取失败!")
                }
            })
        },
        getThumbs(){
            this.$http.get('api/getthumimages/' + this.id).then(result=>{
                if(result.body.status === 0){
                    result.body.message.forEach(item=>{
                        item.w = 600;
                        item.h = 400;
                        item.msrc = item.src
                    })
                    this.list = result.body.message
                }else{
                    Toast("图片详情获取失败!")
                }
            })
        },
        handleClose () {
            console.log('close event')
        }
    },
    components:{
        'comment-box':comment
    }
}
</script>

<style lang="scss" >
    *{
        margin:0;
        padding:0;
    }
    .container{
        padding:0 5px;
        color:#333;
        .title{
            color:#15b4e8;
            font-size:16px;
            padding:6px 0;
            margin-top:5px;
            text-align:center;
            white-space:nowrap;
            text-overflow:ellipsis;
        }
        .subtitle{
            display:flex;
            justify-content:space-between;
            color:#226afe;
        }
        .content{
            font-size:13px;
            line-height:30px;
        }
        /* /deep/ */ .my-gallery {
            display: flex;
            flex-wrap: wrap;
            figure {
                width: 30%;
                margin: 5px;
                img {
                    width: 100%;
                }
            }
        }
    }
</style>